// coding: utf-8
// @Author : lryself
// @Date : 2020/10/30 21:46
// @Software: GoLand

package main

func main() {
	
}
func islandPerimeter(grid [][]int) int {
	c := 0
	for i:=0;i<len(grid);i++{
		for j:=0;j<len(grid[i]);j++{
			if grid[i][j]==1{
				if i-1<0 || grid[i-1][j]==0{
					c++
				}
				if j-1<0 || grid[i][j-1]==0{
					c++
				}
				if i+1>=len(grid) || grid[i+1][j]==0{
					c++
				}
				if j+1>=len(grid[i]) || grid[i][j+1]==0{
					c++
				}
			}
		}
	}
	return c
}